package top.sigetech.springcloud.controller;


import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import top.sigetech.springcloud.entity.Payment;
import top.sigetech.springcloud.service.PaymentHystrixFeignService;
import top.sigetech.springcloud.vo.CommonResult;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_global_fallbackMethod")
public class OrderFeignController {
    @Resource
    private PaymentHystrixFeignService paymentHystrixFeignService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String pay_ok(@PathVariable("id")Integer id){
        String result = paymentHystrixFeignService.pay_ok(id);
        log.debug("******查询结果："+result);
        return result;
    }


    @HystrixCommand
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    public String pay_timeout(@PathVariable("id")Integer id){
        String result = paymentHystrixFeignService.pay_timeout(id);
        log.debug("******查询结果："+result);
        return result;
    }
    public String payment_hystrix_fallback(Integer id){
        return "我是消费者，对方支付系统繁忙，请稍后再试";
    }
    // 下面的是全局 fallback 方法
    public String payment_global_fallbackMethod(){
        return "全局处理";
    }
}
